home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / sleep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  1.0 KB  |  55 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  *   Some simple sleep routines - use a busy wait loop for the system counter
  6.  * to catch up with us.  usleep() is the same as sleep() except that it takes
  7.  * micro seconds (us) instead (note that the resolution is only 5ms).
  8.  *
  9.  * $Header: sleep.c,v 1.1 88/02/03 22:46:50 m68k Exp $
  10.  *
  11.  * $Log:    sleep.c,v $
  12.  * Revision 1.1  88/02/03  22:46:50  m68k
  13.  * Initial revision
  14.  * 
  15.  */
  16. #include    <osbind.h>
  17. #include    <sysvars.h>
  18. #include    <types.h>
  19.  
  20. #define    HZ        200
  21. #define    USEC_TO_HZ(us)    (((us) + 1000000/HZ - 1) / 1000000/HZ)
  22.  
  23. static long    time_now();
  24.  
  25. void
  26. sleep(n)
  27.     int    n;
  28. {
  29.     long    stop;
  30.  
  31.     stop = Supexec(time_now) + n * HZ;
  32.     while (Supexec(time_now) < stop)
  33.         ;
  34. }
  35.  
  36. /*
  37.  * Same as long but has in units of 1/HZ of second
  38.  */
  39. void
  40. usleep(usec)
  41.     u_long    usec;
  42. {
  43.     long    stop;
  44.  
  45.     stop = Supexec(time_now) + USEC_TO_HZ(usec);
  46.     while (Supexec(time_now) < stop)
  47.         ;
  48. }
  49.  
  50. static long
  51. time_now()
  52. {
  53.     return *_hz_200;
  54. }
  55.